package com.teach.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.teach.R;
import com.teach.dto.LoginUser;
import com.teach.entity.Report;
import com.teach.service.CommentsService;
import com.teach.service.ReportService;

/**
 * <pre>
 * 举报控制器
 * 创建时间 ：     2019年12月26日 下午5:18:55
 * 当前版本 ：     V1.0
 * 版权 ：            舒星所有
 * </pre>
 * @author 舒星
 *
 */
@Controller
@RequestMapping("/report")
public class ReportController {
	@Autowired
	private ReportService service;
	@Autowired
	private CommentsService commentService;
	/**
	 * 添加举报信息
	 * @param reportCommentId
	 * @param reportContent
	 * @param user
	 */
	@RequestMapping("/report-add.do")
	@ResponseBody
	public Object doAdd(Long reportCommentId,String reportContent,LoginUser user) {
		try{
			Report report=new Report();
			report.setReportCommentId(reportCommentId);
			report.setReportContent(reportContent);
			report.setReportUserName(user.getUserName());
			service.insertReport(report);
			return R.ok();
		}catch(Exception e){
			e.printStackTrace();
			return R.error("举报失败");
		}
		
	}
	@RequestMapping("/report-list.do")
	@ResponseBody
	public Object doList(Integer current) {
		int rowMax=10;
		int page=1;
		if(current!=null) {
			page=current;
		}
		return service.pageReport(page, rowMax);
	}
	@RequestMapping("/report-handle.do")
	@ResponseBody
	public Object doHandle(Long reportId,Boolean handle) {
		try{
			service.modifyReport(reportId);
			Long commentId=service.get(reportId).getReportCommentId();
			if(handle) {
				commentService.commentsRemove(commentId);
			}
			return R.ok();
		}catch(Exception e) {
			e.printStackTrace();
			return R.error("处理失败");
		}
	}
}
